<?php
set_time_limit(0);
header("Content-type:text/html;charset=utf-8");
include_once dirname(dirname(__FILE__)) . '/nn_logic/nl_common.func.php';
include_once dirname(dirname(__FILE__)) . '/mgtv_v2/mgtv_init.php';
include_once dirname(dirname(__FILE__)) . '/mgtv_v2/models/queue_task_model.php';
define('XIAOLE_MOIVE_IMPORT_SP', 'gdgd_xiaole');
$dc = nl_get_dc(array(
		'db_policy' => NL_DB_WRITE,
		'cache_policy' => NP_KV_CACHE_TYPE_MEMCACHE
));
$last_data = null;
$sql="select nns_id,nns_cp_id from nns_vod where nns_id in('28dbdf409e5bef4412ace0446077527f',
'c574a30dea95069ed185351d92b4fe59',
'1697c1ef03106def079210d30bf5c332',
'2e49bbe2eed4e5d77a449cfcbef29ff3',
'a52955acb3f59755804cea7fa2a2726f',
'8e84db3a8ee3be60e09a548c334709b2',
'f39787dffb8a073e486d6a9c089f617f',
'cc64fe5e55f802fca3e738067d50bdb2',
'5e16996a4e86bed6f36a230b8f9a5ebd',
'678839bf0cff4d11879aacc9375d7450',
'4acb077f1f8f189f85ccbadefcfa1983',
'0ee1fe6231ca69d59bcfad88cdf562c0',
'c8b95b29750b0c2dcbea16eaf3f51bde',
'9d836a5d28a038974045080f4746b83d',
'9cf4e9e2c20aff3060469d485245bfa7',
'9d836a5d28a038974045080f4746b83d',
'9cf4e9e2c20aff3060469d485245bfa7',
'e42a222c82625129860acc2034272ae2',
'4cf7541381974761bb927f06015b2a85',
'd899b96a65901ed40d59796880014e48',
'c5bc9fac8dda4201c2cc8db0f003b9c1',
'd2849e93ca2dc30cc77589d4b39aa0ee',
'd8c6f9c0bbc281743db15508da09c17b',
'6e8e190f10f07bd4d3812185ffe6f5b3',
'b4848c36695b86c965907cf7e0d4bb78',
'da1b8e3a2a0fc8585674adb57849e269',
'435bc6e697a7ed6f74764fe74be44ec9',
'48782c91c6fe8cb1acad7f7563e244ec',
'dae98d32a17a622682e714d43f7bd496',
'ca6833c5d15543ce3d2f0f6320b67dfc',
'5369b0814bcf17e7afd1570a72746512',
'58a2c67375d6a1ec6512e522fa166ca9',
'4b2761e22b611b739cd0676c2f3ba81a',
'b7eef83fd15cfacb22be4e65b0cb9ed5',
'bc3de30e00656c6506da178948231fbb',
'59990f50bd129443514188b615c3b29d',
'68c4b00c22a1de241a37fa3ef9ae235b',
'db4c1852eff07e988880ee097544feba',
'7351ff91a58ee37dd6e6e8fb9bed199a',
'7fc7c1cf74f1d37a33a5c768e37adc8d',
'fc7dbda2ffc9e8db68e7c79541cee7bb',
'9481080891e8032018fc44cb2b9feb22',
'27d9beb63d1fc3f6d2fef766fc456f4e',
'0d168d2ec2f0a778777cf154f8d0ab5c',
'749b9d696446650102b5809895a4591c',
'1b7f1fcafc390ce8fe96ee186fb342da',
'30342b145c978da7f672dcdbf0547721',
'12665c37ed7ddde36670cd79aeddd958',
'd00eb1b9a57fb80d8e87da407de8a187',
'ffbb4ac1ec07e5b89c541baf4ef71ebe',
'f61cfa4024f25c11a63aeda6d1b519f3',
'c354a71c03628cf0c7e86b3cf16ab219',
'a7dc300be2ccd963daef9427c44525b4',
'82ae58a6cbdea0f523342a0c2fb997e0',
'58bd9493a4834839bbcc06e5b43bbe45',
'8a864eef63caa81f52538aa77015e98c',
'430491370eab8c01295b1ce1952da0d9',
'eccaff501acb6464cf1704ab95997b83',
'fbeb63da6911c897c39f028ddc7d50c5',
'e046b7e7648fb3e6f9ba7b3ff44bc7de',
'9eb8b17d3d16ea44f7477bbc8c54c6c6',
'074cdcdc5423f56de9fa5b60fd74d7ed',
'd8bc4d43cc81f2c29ec92e090603ab58',
'1dc9459a898f349e59913d12297543dc',
'586344a1e06483edee126b5553823496',
'f24133e53d10ee02990292c467800eaa',
'e2b64c3182eeedd72399cdd4696197b7',
'2809d1e5a292524b7c8ae52520de8409',
'dfcf8a729e0bf5dc2d34df79925c5a8a',
'd3033380d024c7ed635431a3b375ac10',
'e39dc0be8dc9f0657c12651dc342617c',
'e30a3c3f751ce2fce3382b23209bdc30',
'c1938d28846906afc5dd60d9c78b4f55',
'f84c8c73b4773c43223b323b542af8cb',
'eabefe004791c1e8a489c584d9e8f8a5',
'af5630adc61d4c7770b9a55faada1971',
'a00439bc466857e33b46aeff49289620',
'79718b545d32723073174aa1eb8c20c0',
'b463c73459b7a9bb767ef29a96e53ff0',
'291307cb50929fe101d8619b31e162a8',
'bf1f5e7814d8917fef783434713e569d',
'11b099df37632fd75700d9cabf1fe2d5',
'09b73dadad5c419bc0479c62e47cfb71',
'26876b40783587f21bb8fb33809b005f',
'002762e72184bc2c761641239d6562a4',
'42c3ef26c15ef9e8b70c8a7ab249c027',
'8479bb403f69aca03060af687bc47f8a',
'1f7a3786bdfba2342696d44c60938936',
'4c7edd767707a98d23cda0056beb4f3e',
'4ac0bb93b402f328cb7868a72fe348f4',
'0e8eef4a07b5cb4fccdde68cf5f1c56b',
'56efa0045a8867e5a4d856b8da5a0db3',
'7918d27bc13703ff7eb369d53dcc03b7',
'74c4f66b1bda9d38d7802c3d63d6a426',
'70e02f6c99bc3a237672784179d2013d',
'50b75ff759501d608dde8ddf553aea21',
'51e207e9cd3a10b6df24d37ae7ecc741',
'4770699e9f07c338ef5ab7a19f8669f4',
'003d6e3014727093832c1027fc99cf92',
'2b5af875963a61f1a5ffb5594384b1d6',
'1df92e3171b72412f0a796e5d3d9a811',
'876893c27452f837c01e5398eb5ff146',
'7976348014c5c5e762db73f6420ffb78',
'1984287ef97cd98ee2e6228e51060396',
'4560840c96055807c1b3754a4ff2f5e0',
'0a3c7b303a534f5ee2ed5eab9992c051',
'9d1066b80816562932e965dd30523575',
'4a8cdfa4c28106a59ad34f842148d75e',
'f7f18eea1f123c7cbd98df739df9b3de',
'd7dc5e96e3d3039a37f58cc852c4a885',
'8346a2f89825d0a22331b2ed65710310',
'525b17243f58b357d27314b9f24b7a7b',
'bcd63e3e881e46aa7922133396bdaacd',
'a4f5dd8e6434e94a5de0485f2525c8d0',
'581b5eb6abdefdfb5ac345faccb4601c',
'd2248b2b02f7f3e17c316880b8e3d4ec',
'4a75f2318569b7bc434e527695a7a8fd',
'52c0d5df669e3597f4d1ff9c521be462',
'384be1f0b523ae7c9ae2e1dc16ff0fc6',
'0acde37a573d4200cb3a26d9e7f1a466',
'41f01ed0f37edb9f0065e480b9a7f351',
'3ce44e98377e0b0b5083cfc14dd0b9bd',
'e0412472cb95cd7e8c7eb2d55113619d',
'c869666511ca45e7ec740e85fa92e192',
'7182dbd81fdaee9e186104711609c4fd',
'ca39c8d58186289319a060660c489f8a',
'625d76f77a631a8cd9be08d49a0816c7',
'c0369b8178d1e41ba7ff4bdbb23ec336',
'1d10dcd74ea5142e300f2a2e82094e7b',
'ed5d2650ca8dbe7b8da71e8bdaa0eb1e',
'56cd0ebb90758f673c73f3ebe719d490',
'9b7dd656812b3d62104d101b5b142372',
'ccb548fc92e0bd88e4a50d54da9ac959',
'f50b083be8c59c0736807b02283056ee',
'c5b10b9b78f817bfe1dae02c93e1d889',
'bba6f787be240c4b410eb4d0af88f5a5',
'a732f710d96b5317507f4e398de44ce4',
'5c9a885282e3e9deb562575ae1f7a57c',
'fb0776fcb6e545b5b8d93838988bc79b',
'c9c4247e332ef538c8219511816218a3',
'cfe4499dbd121855426a2857f5fb00aa',
'ecdab19ffc2bd6da6c32b34781cf97d9',
'e387e9125bd5ff11e14a03e4d2c7c734',
'a74cf2d31c5bda7d84ca8f4042e8105b',
'd36cab3098c02c8bbf4a9ba0e62cf912',
'c8ee67a4cff5ca6d2a224b0d940e6ec3',
'5c4067999154dbc841dc9946455201f2',
'28312c1d5579ef3fc951aa39fc1978b0',
'83c8339f259c8e7334be5c78ca662d26',
'4ade46e171ed360e526950f600bea44e',
'58dbca96491dd840985301da9fdfa976',
'5a7061a0f569ddedcfc94f4cefafbf11',
'9e1484e11cfbcbe99225830bc52fb92b',
'4294591c02e17a5e82b76bfa91b87ea4',
'4606847c75be8214c721ab5276f29f13',
'136fcfc923ba6c52853105046e4396bc',
'd432ea1ed41e0a2333353159ff5c130b',
'fbc61e7e343c62de90fa4537a6e1b12c',
'95dd4e1018be5481164ad6388dfe0ea2',
'b2bc1ab94035e907d52869a7c9899def',
'94a03b6150086c7d453d0bbbcdd2b2b5',
'7bf20c42598e9817e13107e4386cf060',
'91e8a7e2f477d12c238ec305df489da0',
'1898bd38b449357ff44d89fb795d5401',
'28907629453d4e44bb5de2e632cc5046',
'271042d6e4ebfce5974099be87d6a2a5',
'06677c4d096ad16781952277239ea3c4',
'6cd0b6772d4208b80e1048bbf7dbf4d1',
'6e2fc0a9d121bc87327dd71899afd102',
'6f077c10c2e256f3f9ff927086d5d526',
'74e344b739e0263621f805ee02473857',
'3687072b7d4dd7804c06490ca59ea77e',
'03486fd72a4a6c4c8e850e8b08febb73',
'8828b5ac82dd3bd3ef4c1cc292e15dd2',
'b6f4fd7d8a7439d787e24ec104e3a0f9',
'd1d25d982196b49b95220701b07552ce',
'badf9adf04afc0268e9373e7df650336',
'68d1a8bc64b7b25b56f601b9158812d5',
'65fddc2c2e9bc012352e3afa0de8720a',
'6caed81c87108d2136d8596665e09c69',
'6fe6563928e9cb84e56d8c38b5177480',
'646869771ae47789fa92cd7803c3425a',
'641c145708a22160622fb9c489083003',
'5bc5313e5a090e7ee96c27bac81d42f3',
'4607c543cc4f1e140e8f4b9f2dbc07c8',
'0c8ed91d06226393316ad3586993b5b5',
'43a72be952845a8d032ea8b937b5d3b9',
'565986380945a38ed8aefbfdabe24c45',
'30fced805117d6619ca26cc4cc3100b7',
'1eee17e678830f094206162906d4e9c4',
'11a1c05b1aec83d810b1242b2b68bd0e',
'2f5d04efc92f0e91cda287a90eb00ebe',
'e41b6059df5bb7fb5c19726ac23e6661',
'eb7956a6a3f5884395add2929cc8b66f',
'eaabd8f624ceed6748d86c4958f7d56e',
'c80d207ac8097db71de36b2c6d514dfa',
'86b2481daf6d5255662982ac9d13ebb2',
'a3e1b53a62c3a84dff9c38ad176bc98e',
'cc3c249c73483d28d652b43f0eb77ead',
'ba8f79160a0b02f53394a898321e5433',
'9ce59f103236613adcd68fcc58ab5639',
'b858052a24a5c2497d7ca1602a4242b4',
'50083911f76b371c85cf748a73e93c88',
'84733b46a760562e0b6c935e36299835',
'6a3a30887bfcbd1c79c6de8d8d4b1085',
'6ad7d605fea9a74a192cfed41a0db250',
'779e9d5921762decae1c09c5deb0305f',
'b61c171d4bdeee03485a72652ed2acd3',
'e4c52369cde2674c300bc42725efba5f',
'23b5b9bdde316ceba4e5457e27002072',
'9feafac493d1e59ffc5745574945083c',
'24bb43fc16d1bdc3ca1c4af672ddb771',
'413d5d992f542e183cdf4a528a09ce88',
'25d8279f78c37aecab635b407df70b94',
'7e6ff3e9bdf02a97fef0ba78991595e5',
'80adcb435878cf2e4052883c54fc75d6',
'750aec20f043cd30106836d320516992')";

$queue_task_model = new queue_task_model();

$result_vod = nl_query_by_db($sql,$dc->db());
$arr_count=array();
if(is_array($result_vod) && !empty($result_vod))
{
    
    $temp = array();
    foreach ($result_vod as $xiaole_vod_key=>$xiaole_vod_val)
    {
        if(isset($arr_count[$xiaole_vod_val['nns_cp_id']]))
        {
            $arr_count[$xiaole_vod_val['nns_cp_id']]++;
        }
        else
        {
            $arr_count[$xiaole_vod_val['nns_cp_id']] = 1;
        }
        $sql_index = "select * from nns_vod_index where nns_vod_id ='{$xiaole_vod_val['nns_id']}'";
        $result_index = nl_query_by_db($sql_index,$dc->db());
        if(!$result_index || empty($result_index) || !is_array($result_index))
        {
            continue;
        }
        foreach ($result_index as $xiaole_index_key=>$xiaole_index_val)
        {
            $sql_media="select * from nns_vod_media where nns_vod_index_id ='{$xiaole_index_val['nns_id']}' and nns_vod_id='{$xiaole_vod_val['nns_id']}' ".
                " and nns_deleted !='1' and nns_encode_flag='0' and nns_cp_id='fuse_xiaole_encode' and (nns_content_id='' or isnull(nns_content_id)) and (nns_media_service='' or isnull(nns_media_service)) order by nns_kbps asc,nns_create_time desc limit 1";
//             echo $sql_media."<hr/>";
            $result_media = nl_query_by_db($sql_media,$dc->db());
            if(!$result_media || empty($result_media) || !is_array($result_media))
            {
                continue;
            }
            $last_data['index'][] = $xiaole_index_val['nns_id'];
            $last_data['media'][] = $result_media[0]['nns_id'];
            if(isset($last_data['video'][$xiaole_vod_val['nns_id']]))
            {
                continue;
            }
            $last_data['video'][$xiaole_vod_val['nns_id']] = $xiaole_vod_val['nns_id'];
        }
    }
    if(isset($last_data['video']))
    {
        $last_data['video'] = array_values($last_data['video']);
    }
}
echo json_encode($last_data);die;
$count = 0;
foreach ($last_data as $key=>$val)
{
    
    foreach ($val as $_k=>$_v)
    {
        if($_k=='media')
        {
            $count++;
        }
//         $queue_task_model = new queue_task_model();
//         $queue_task_model->q_add_task($_v, $key, 'add',XIAOLE_MOIVE_IMPORT_SP,null,true);
//         unset($queue_task_model);
    }
}
var_dump($count,$arr_count);